#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <unistd.h>

void handle_exit(int signo)
{
	fflush(stdout);
	if(signo == SIGINT || signo == SIGTERM)
		exit(EXIT_SUCCESS);
}

int main(int argc, char* argv[])
{
	signal(SIGINT, handle_exit);
	signal(SIGTERM,handle_exit);

	while(1)
	{
		printf("this is a test for IO buffer.\n");
		// must flush the stream to write to file,
		// else redirect or file would has nothing.
		// even the process is terminated or killed.
		//fflush(stdout);
		sleep(1);
	}
}

